package com.unicom.projt.ivr;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.Html;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.unicom.projt.Home;
import com.unicom.projt.InputPhoneNumberPage;
import com.unicom.projt.Main;
import com.unicom.projt.R;
import com.unicom.projt.util.AlertDialogUtils;
import com.unicom.projt.util.PageJumpUtils;
import com.unicom.projt.util.SystemUtils;
import com.unicom.projt.util.UserHolder;

/**
 * Created by IntelliJ IDEA.
 * User: Lee
 * Date: 11-12-17
 * Time: 下午5:15
 */
public class UnBindCardPage extends Activity implements View.OnClickListener{
//    private TextView mTextView1;
//    private TextView mTextView2;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.un_bind_card);
        ((TextView)this.findViewById(R.id.un_bind_card_number_txt)).setText(UserHolder.phoneNumber);
//        mTextView1 = (TextView) this.findViewById(R.id.un_bind_card_txt1);
//        mTextView2 = (TextView) this.findViewById(R.id.un_bind_card_txt2);
//        mTextView1.setText(Html.fromHtml("银行卡缴费解除绑定流程可以语音拨打101707或发送短信至101707两种方式进行。<br>具体操作如下:<br>" +
//                "1、语音操作流程："));
/*
        mTextView2.setText(Html.fromHtml("2、短信操作：用户发送QX至101707<br>" +
                "<br>说明：<br>" +
                "●注册用户连续<font color='red'>3个月</font>未充值的，系统自动解除其绑定关系。<br>" +
                "●客户注销本业务后，如需重新注册绑定新的银行卡，需等一个月方可办理。如重新注册绑定原银行卡则不受此限制。"));
*/
        this.findViewById(R.id.un_bind_card_back_btn).setOnClickListener(this);
        this.findViewById(R.id.un_bind_card_logout_btn).setOnClickListener(this);
        this.findViewById(R.id.un_bind_card_call_btn).setOnClickListener(this);
        this.findViewById(R.id.un_bind_card_sms_btn).setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.un_bind_card_back_btn:
                PageJumpUtils.jump(this, Home.class);
                this.finish();
                break;
            case R.id.un_bind_card_logout_btn:
                AlertDialogUtils.showYesNoDiaLog(this, "是否注销？", new AlertDialogUtils.Executor() {
                    @Override
                    public void execute() {
                        UserHolder.clean();
                        doLogout();
                    }
                });
                break;
            case R.id.un_bind_card_call_btn:
                call();
                break;
            case R.id.un_bind_card_sms_btn:
                sendSMS();
                break;
        }
    }

    private void sendSMS() {
        Uri uri = Uri.parse("smsto:101707");
        Intent it = new Intent(Intent.ACTION_SENDTO, uri);
        it.putExtra("sms_body", "QX");
        startActivity(it);
    }

    private void call() {
//        Intent myIntentDial = new Intent(Intent.ACTION_CALL,Uri.parse("tel:" + "10086"));
        Intent myIntentDial = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + "101707"));
        startActivity(myIntentDial);
    }

    private void doLogout(){
        Intent intent = new Intent(this, InputPhoneNumberPage.class);
        this.startActivity(intent);
        this.finish();
    }
    @Override
    public void onBackPressed() {
        PageJumpUtils.jump(this, Home.class);
        this.finish();
    }
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_SEARCH) {
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}

